// pages/admin/order.js
import { Admin } from '../../model/admin.js';
var admin = new Admin();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    store_id: '',
    hidden: false,
    start_date: '请选择',
    end_date: '请选择',
    list: [],
    show: false,
    minDate: new Date().getTime() - (86400000 * 31 * 3),
    maxDate: new Date().getTime(),
    sum: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDataList()
  },

  /**
   * 获取全部记录
   */
  getDataList() {
    wx.showLoading({
      title: '加载中',
    });
    var start_date = ''
    if (this.data.start_date != '请选择') {
      start_date = this.data.start_date
    }
    var end_date = ''
    if (this.data.end_date != '请选择') {
      end_date = this.data.end_date
    }
    admin.getOrderNumByStore({ start_time: start_date, end_time: end_date }, (res) => {
      this.setData({
        list: res.data,
        sum: res.sum
      })
      wx.hideLoading();
    })
  },
  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
  },
  onConfirm(event) {
    const [start, end] = event.detail;
    this.setData({
      show: false,
      start_date: this.formatDate(start),
      end_date: this.formatDate(end)
    });
  },
  openList(e) {
    wx.navigateTo({
      url: `order_list?id=${e.currentTarget.dataset.id}&name=${e.currentTarget.dataset.name}`,
    })
  }
})